package com.amoyhong.hongWhether.model;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;

import java.lang.reflect.Type;

/**
 * Created by Administrator on 2016/3/20.
 */
public class NetworkResponse {

    private boolean isSuccessful;

    private String message;

    public NetworkResponse(boolean isSuccessful, String message) {
        this.isSuccessful = isSuccessful;
        this.message = message;
    }

    public static class NetworkResponseDeserializer implements JsonDeserializer<NetworkResponse> {

        @Override
        public NetworkResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {

            JsonObject jsonObject = json.getAsJsonObject();

            boolean isSuccessful = jsonObject.get("success").getAsBoolean();
            String message = jsonObject.get("message").getAsString();

            NetworkResponse response = new NetworkResponse(isSuccessful, message);

            return response;
        }
    }

    public boolean isSuccessful() {
        return isSuccessful;
    }

    public String getMessage() {
        return message;
    }
}
